package com.indusfo.spc.client.controller;

import com.indusfo.spc.annotation.UserLoginToken;
import com.indusfo.spc.client.pojo.WorkStation;
import com.indusfo.spc.client.service.WorkStationService;
import com.indusfo.spc.vo.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * 工站报工
 * @author chenm
 * @create 2019-12-04 20:53
 */
@RestController
@RequestMapping("/client/workStation")
public class WorkStationController {

  @Autowired
  private WorkStationService workStationService;


  /*
  首工位报工
  */
  @PostMapping("/firstJobWork")
  @UserLoginToken
  public JSONObject firstJobWork(@RequestBody Map<String,Object> models){
    try{
      return workStationService.firstJobWork(models);
    }catch (Exception e){
      e.printStackTrace();
      return JSONObject.build(JSONObject.ERROR,"系统异常，联系管理员");
    }
  }


  /*
  工位报工
  */
  @PostMapping("/jobWork")
  @UserLoginToken
  public JSONObject jobWork(@RequestBody WorkStation workStation) {
    try {
      if(null == workStation.getStationId()){
        return JSONObject.build(JSONObject.ERROR,"工位不能为空");
      }
      if(null == workStation.getUserId()){
        return JSONObject.build(JSONObject.ERROR,"作业人员不能为空");
      }
      if(null == workStation.getFlag()){
        return JSONObject.build(JSONObject.ERROR,"是否一次完工不能为空");
      }
      if(null == workStation.getJump()){
        return JSONObject.build(JSONObject.ERROR,"是否跳序不能为空");
      }
      return workStationService.jobWork(workStation);
    }catch (Exception e){
      e.printStackTrace();
      return JSONObject.build(JSONObject.ERROR,"系统出错");
    }
  }



}
